package com.hua.Thread.ThreadPool1;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author: _hua
 * @created: 2019/3/10.
 * @updater:
 * @description:
 */
public class ScheduledThreadPoolTest {
    public static void main(String[] args) {
       // delay();
        System.out.println("Start============");
        cycle();

    }

    private static void cycle() {
        ScheduledExecutorService scheduledThreadPool= Executors.newScheduledThreadPool(3);
        scheduledThreadPool.scheduleAtFixedRate(new Runnable(){
            @Override
            public void run() {
                System.out.println("延迟5秒后每2秒执行一次");
            }
        },5,2,TimeUnit.SECONDS);

    }

    private static void delay() {
        ScheduledExecutorService scheduledThreadPool= Executors.newScheduledThreadPool(3);

        scheduledThreadPool.schedule(new Runnable(){
            @Override
            public void run() {
                System.out.println("延迟三秒");
            }
        }, 3, TimeUnit.SECONDS);
    }



}
